//
//  LSHomeHotMatchCell.m
//  LookScore
//
//  Created by wr on 2018/4/25.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSHomeHotMatchCell.h"
@interface LSHomeHotMatchCell()

@property(strong,nonatomic)UIImageView *homeTeamLogo;

@property(strong,nonatomic)UILabel *homeTeamName;

@property(strong,nonatomic)UIImageView *guestTeamLogo;

@property(strong,nonatomic)UILabel *guestTeamName;

@property(strong,nonatomic)UIImageView *scoreBoard;

@property(strong,nonatomic)UILabel *homeTeamScore;

@property(strong,nonatomic)UILabel *guestTeamScore;

@property(strong,nonatomic)UILabel *timeLable;

@property(strong,nonatomic)UILabel *leaguenameLable;

@property(strong,nonatomic)UILabel *roundCountLable;

@property(strong,nonatomic)UILabel *matchStateLab;

@end



@implementation LSHomeHotMatchCell

+(LSHomeHotMatchCell *)HomeHotMatchCellByTableView:(UITableView *)tableView{
    LSHomeHotMatchCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSHomeHotMatchCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    
    
    
    [self.contentView addSubview:self.homeTeamLogo];
    [self.contentView addSubview:self.homeTeamName];
    
    [self.contentView addSubview:self.guestTeamLogo];
    [self.contentView addSubview:self.guestTeamName];
    
    [self.contentView addSubview:self.scoreBoard];
    [self.scoreBoard addSubview:self.homeTeamScore];
    [self.scoreBoard addSubview:self.guestTeamScore];
    
    [self.contentView addSubview:self.timeLable];
    [self.contentView addSubview:self.leaguenameLable];
    [self.contentView addSubview:self.roundCountLable];
    [self.contentView addSubview:self.matchStateLab];
    

    self.scoreBoard.sd_layout.centerXEqualToView(self.contentView).centerYEqualToView(self.contentView).widthIs(100).heightIs(40);
    
    self.homeTeamLogo.sd_layout.rightSpaceToView(self.scoreBoard,29).centerYEqualToView(self.scoreBoard).widthIs(40).heightIs(40);
    self.homeTeamName.sd_layout.centerXEqualToView(self.homeTeamLogo).topSpaceToView(self.homeTeamLogo, 0).widthIs(95).heightIs(20);
    self.homeTeamScore.sd_layout.leftEqualToView(self.scoreBoard).centerYEqualToView(self.scoreBoard).widthIs(40).heightIs(40);
    
    self.leaguenameLable.sd_layout.centerXEqualToView(self.scoreBoard).bottomSpaceToView(self.scoreBoard, 5).widthIs(50).heightIs(20);
    self.timeLable.sd_layout.rightSpaceToView(self.leaguenameLable, 5).bottomSpaceToView(self.scoreBoard, 5).widthIs(35).heightIs(20);
    self.roundCountLable.sd_layout.leftSpaceToView(self.leaguenameLable, 5).bottomSpaceToView(self.scoreBoard, 5).widthIs(35).heightIs(20);
    
    self.matchStateLab.sd_layout.centerXEqualToView(self.scoreBoard).topSpaceToView(self.scoreBoard, 0).widthIs(90).heightIs(20);
    
    self.guestTeamLogo.sd_layout.centerYEqualToView(self.scoreBoard).leftSpaceToView(self.scoreBoard, 29).widthIs(40).heightIs(40);
    self.guestTeamName.sd_layout.centerXEqualToView(self.guestTeamLogo).topSpaceToView(self.guestTeamLogo, 0).widthIs(95).heightIs(20);
    self.guestTeamScore.sd_layout.rightEqualToView(self.scoreBoard).centerYEqualToView(self.scoreBoard).widthIs(40).heightIs(40);
}

- (void)setHotMatchModel:(LSHomeHotMatchModel *)hotMatchModel{
    _hotMatchModel = hotMatchModel;
    self.homeTeamScore.text = self.hotMatchModel.HomeTeamScore;
    self.homeTeamName.text = self.hotMatchModel.HomeTeamName_CN;
    
//    [self.homeTeamLogo sd_setImageWithURL:[NSURL URLWithString:hotMatchModel.HomeTeamImg]];
//    [self.homeTeamLogo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://101.132.148.59:303/MatchData/Team/image/%@.png",hotMatchModel.HomeTeamId]] placeholderImage:[UIImage imageNamed:@"logoNull"] options:SDWebImageRefreshCached];
    
    
    self.timeLable.text = [self getTimeStrWithStr:hotMatchModel.MatchDateTime];
    
    self.leaguenameLable.text = hotMatchModel.LeagueName_CN;
    
//    self.roundCountLable.text = hotMatchModel.RoundNumber;
    
    if (hotMatchModel.RoundNumber.length != 0) {
        self.roundCountLable.text = [NSString stringWithFormat:@"第%@轮",hotMatchModel.RoundNumber];
    }else{
        self.roundCountLable.text = @"";
    }
    
//    self.matchInfoLab.text = [NSString stringWithFormat:@"%@ %@ %@轮",timeStr,hotMatchModel.LeagueName_CN,hotMatchModel.RoundNumber];
    
    if (self.hotMatchModel.MatchState == 0) {
        self.matchStateLab.text = @"未开赛";
    }else if (self.hotMatchModel.MatchState == 1){
        self.matchStateLab.text = @"上半场";
    }
    else if (self.hotMatchModel.MatchState == 2){
        self.matchStateLab.text = @"中场";
    }
    else if (self.hotMatchModel.MatchState == 3){
        self.matchStateLab.text = @"下半场";
    }
    else if (self.hotMatchModel.MatchState == 4){
        self.matchStateLab.text = @"加时";
    }
    else if (self.hotMatchModel.MatchState == 5){
        self.matchStateLab.text = @"点";
    }
    else if (self.hotMatchModel.MatchState == -1){
        self.matchStateLab.text = @"结束";
    }
    self.guestTeamScore.text = self.hotMatchModel.GuestTeamScore;
    self.guestTeamName.text = self.hotMatchModel.GuestTeamName_CN;
    

    [self.homeTeamLogo sd_setImageWithURL:[NSURL URLWithString:TeamImageHeaderUrl((long)hotMatchModel.HomeTeamId)] placeholderImage:[UIImage imageNamed:@"logoNull"] options:SDWebImageRefreshCached];
    
    
    
    
    [self.guestTeamLogo sd_setImageWithURL:[NSURL URLWithString:TeamImageHeaderUrl((long)hotMatchModel.GuestTeamId)] placeholderImage:[UIImage imageNamed:@"logoNull"] options:SDWebImageRefreshCached];
    
}

- (NSString *)getTimeStrWithStr:(NSString *)timeStr{
    
    NSString * timeStr1 = [timeStr componentsSeparatedByString:@"T"].lastObject;
    NSArray * array1 = [timeStr1 componentsSeparatedByString:@":"];
    NSMutableArray * array2 = [NSMutableArray arrayWithArray:array1];
    [array2 removeLastObject];
    NSString * str = [array2 componentsJoinedByString:@":"];
    return str;
}
- (UIImageView *)homeTeamLogo{
    if (!_homeTeamLogo) {
        _homeTeamLogo = [[UIImageView alloc] init];
    }
    return _homeTeamLogo;
}

- (UIImageView *)guestTeamLogo{
    if (!_guestTeamLogo) {
        _guestTeamLogo = [[UIImageView alloc] init];
        
    }
    return _guestTeamLogo;
}

- (UILabel *)homeTeamName{
    if (!_homeTeamName) {
        _homeTeamName = [[UILabel alloc] init];
        _homeTeamName.font = LSFontSize13;
        _homeTeamName.textAlignment = NSTextAlignmentCenter;
    }
    return _homeTeamName;
}

- (UILabel *)guestTeamName{
    if (!_guestTeamName) {
        _guestTeamName = [[UILabel alloc] init];
        _guestTeamName.font = LSFontSize13;
        _guestTeamName.textAlignment = NSTextAlignmentCenter;
    }
    return _guestTeamName;
}

-(UILabel *)homeTeamScore{
    if (!_homeTeamScore) {
        _homeTeamScore = [[UILabel alloc] init];
        _homeTeamScore.textColor = [UIColor whiteColor];
        _homeTeamScore.textAlignment = NSTextAlignmentCenter;
        _homeTeamScore.backgroundColor = [UIColor clearColor];
    }
    return _homeTeamScore;
}

-(UILabel *)guestTeamScore{
    if (!_guestTeamScore) {
        _guestTeamScore = [[UILabel alloc] init];
        _guestTeamScore.textColor = [UIColor whiteColor];
        _guestTeamScore.textAlignment = NSTextAlignmentCenter;
        _guestTeamScore.backgroundColor = [UIColor clearColor];
    }
    return _guestTeamScore;
}

- (UIImageView *)scoreBoard{
    if (!_scoreBoard) {
        _scoreBoard = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomeScoreBoard"]];
        
    }
    return _scoreBoard;
}
- (UILabel *)matchStateLab{
    if (!_matchStateLab) {
        _matchStateLab = [[UILabel alloc] init];
        _matchStateLab.font = LSFontSize12;
        _matchStateLab.textAlignment = NSTextAlignmentCenter;
    }
    return _matchStateLab;
}

- (UILabel *)timeLable{
    if (!_timeLable) {
        _timeLable = [[UILabel alloc] init];
        _timeLable.font = LSFontSize12;
        _timeLable.textColor = LSSubColor5D5D5D;
        _timeLable.textAlignment = NSTextAlignmentCenter;
    }
    return _timeLable;
}

- (UILabel *)leaguenameLable{
    if (!_leaguenameLable) {
        _leaguenameLable = [[UILabel alloc] init];
        _leaguenameLable.font = LSFontSize12;
        _leaguenameLable.textColor = LSSubColor5D5D5D;
        _leaguenameLable.textAlignment = NSTextAlignmentCenter;
    }
    return _leaguenameLable;
}

- (UILabel *)roundCountLable{
    if (!_roundCountLable) {
        _roundCountLable = [[UILabel alloc] init];
        _roundCountLable.font = LSFontSize12;
        _roundCountLable.textColor = LSSubColor5D5D5D;
        _roundCountLable.textAlignment = NSTextAlignmentCenter;
    }
    return _roundCountLable;
}
@end
